package com.fanshuai.server2;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class SpringWebSocketConfig implements WebSocketConfigurer {
    public SpringWebChatServer chatServer2() {
        return new SpringWebChatServer();
    }

    public ChatServerInterceptor chatServerInterceptor() {
        return new ChatServerInterceptor();
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry
                .addHandler(chatServer2(), "/chat2")
                .addInterceptors(chatServerInterceptor())
                .setAllowedOrigins("*");
    }
}
